//! # Display打印
//!
//!
//!
use std::fmt;
use std::fmt::{Display, Formatter};

fn main() {
    println!("{}", Point2D { x: 23.02, y: 32.03 });
    println!("{}", Mix(3, 9));
}
/// [教程地址](https://rustwiki.org/zh-CN/rust-by-example/hello/print/print_display.html)
///
/// # 例子
///
/// ```
/// let a = add();
/// println!("a={}",a);
/// assert_eq!(3,a);
///```
/// # panic
/// 啊是大方
///
/// # error错误
///
#[allow(unused)]
fn add() -> i32 {
    3
}

#[derive(Debug)]
struct Mix(u32, u32);

impl Display for Mix {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "(#1={},#2={})", self.0, self.1)
    }
}

#[derive(Debug)]
struct Point2D {
    x: f64,
    y: f64,
}

impl Display for Point2D {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "(x={},y={})", self.x, self.y)
    }
}

// 试一试
///
///
/// # 例子

#[derive(Debug)]
struct Complex {
    real: f32,
    image: f32,
}
///
/// ```rust
/// println!("{:?}", Complex( real:32.3,image:3232.23));
/// ```
///
impl Display for Complex {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "Complex {{ real: {}, image: {}}}", self.real, self.image)
    }
}
